package com.iseastar;

import android.content.Intent;
import android.os.Bundle;

import com.iseastar.dianxiaosan.model.Const;
import com.iseastar.guojiang.MainActivity;
import com.iseastar.guojiang.app.AppCache;
import com.iseastar.guojiang.logic.AppLogic;
import com.iseastar.guojiang.model.UserBean;
import com.iseastar.login.LoginActivity;
import com.shouhuobao.station.R;

/**
 * 欢迎界面
 *
 * @author coffee<br>
 * 2016-11-23下午3:23:59
 */
public class SplashActivity extends BaseActivity2 {
    boolean isLogin = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isLogin = AppLogic.checkLogin(getContext());
        // 未登录
        getHandler().postDelayed(runnable, 1000);
    }

    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            if (isLogin == false) {
                startActivity(new Intent(getContext(), LoginActivity.class));
            } else {
                UserBean user = AppCache.getUser();
                if (user.isYiZhan()) {
                    startActivity(com.shouhuobao.take.MainActivity.class);//
                } else {
                    if (user.getState() == Const.CourierRegisterStatus.RegisterOkStatus) {
                        startActivity(MainActivity.class);
                    } else {
                        AppCache.setUser(null);
                        AppCache.setOrder(null);
                        AppCache.setStationOpenInfoBean(null);
                        startActivity(LoginActivity.class);
                    }
                }
            }
            // 不管是否登录、都关闭
            finish();
        }
    };

    @Override
    protected void findViewById() {
        setContentView(R.layout.splash);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        getHandler().removeCallbacks(runnable);
    }
}
